Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

podman: new option --preserve-fd #20866

Merged

Conversation

giuseppe
Copy link
Member

@giuseppe giuseppe commented Dec 1, 2023

add a new option --preserve-fd that allows to specify a list of FDs to pass down to the container.

It is similar to --preserve-fds but it allows to specify a list of FDs instead of the maximum FD number to preserve.

--preserve-fd and --preserve-fds are mutually exclusive.

It requires crun since runc would complain if any fd below --preserve-fds is not preserved.

Closes: #20844

Does this PR introduce a user-facing change?

Now podman run and exec support --preserve-fd to specify the FDs to pass down to the container

@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 1, 2023
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also please split out the logic into a separate function so you can share the conmon setup code between create and exec so we do not have the same logic twice.

preserveFDs := ctr.config.PreserveFDs
preserveFDsMap := make(map[uint]interface{})
Copy link
Member

@Luap99 Luap99 Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use struct{} over interface{} as it doesn't need to store any info.
But maybe do we even have to use a map here at all?
Given you already iterate anyway I think this would be simpler:

files := make([]*os.File, len(ctr.config.PreserveFDsList))
for _, i := range ctr.config.PreserveFDsList {
		if i > preserveFDs {
			preserveFDs = i
		}
		f = os.NewFile()
		files[i] = f
}
cmd.ExtraFiles = files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind this wouldn't work as we do not know the max size without looping over all elements so I the map version is fine with me.

@Luap99
Copy link
Member

Luap99 commented Dec 1, 2023

WDYT about renaming it to just --preserve-fd for the cli. It would have some confusion with --preserve-fds but I find --preserve-fd 5 --preserve-fd 6 more appealing to use because as an user you do not care about the list part in the name.

@rhatdan
Copy link
Member

rhatdan commented Dec 1, 2023

I like --preserve-fd, and then we just explain the difference, Few users will ever do this, so it becomes easily descoverable and the options in the man page will be right next to each other.

@giuseppe giuseppe force-pushed the add-preserve-fds-list branch 2 times, most recently from 79f2812 to f504169 Compare December 1, 2023 13:32
@giuseppe giuseppe changed the title podman: new option --preserve-fds-list podman: new option --preserve-fd Dec 1, 2023
@giuseppe
Copy link
Member Author

giuseppe commented Dec 1, 2023

renamed

@giuseppe giuseppe force-pushed the add-preserve-fds-list branch from f504169 to c772e9d Compare December 1, 2023 15:03
@giuseppe
Copy link
Member Author

giuseppe commented Dec 1, 2023

ready for review

@giuseppe giuseppe force-pushed the add-preserve-fds-list branch 2 times, most recently from 0ea0ff1 to f4b7317 Compare December 4, 2023 12:03
libpod/oci_conmon_common.go Outdated Show resolved Hide resolved
docs/source/markdown/options/preserve-fd.md Outdated Show resolved Hide resolved
test/system/030-run.bats Show resolved Hide resolved
test/system/030-run.bats Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 4, 2023
@giuseppe giuseppe force-pushed the add-preserve-fds-list branch from f4b7317 to db35725 Compare December 4, 2023 13:45
Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And don't forget @Luap99's comment

cmd/podman/containers/run.go Outdated Show resolved Hide resolved
cmd/podman/containers/run.go Outdated Show resolved Hide resolved
docs/source/markdown/options/preserve-fd.md Outdated Show resolved Hide resolved
test/system/030-run.bats Show resolved Hide resolved
add a new option --preserve-fd that allows to specify a list of FDs to
pass down to the container.

It is similar to --preserve-fds but it allows to specify a list of FDs
instead of the maximum FD number to preserve.

--preserve-fd and --preserve-fds are mutually exclusive.

It requires crun since runc would complain if any fd below
--preserve-fds is not preserved.

Closes: containers#20844

Signed-off-by: Giuseppe Scrivano <[email protected]>
@giuseppe giuseppe force-pushed the add-preserve-fds-list branch from db35725 to 01d397a Compare December 5, 2023 09:19
@giuseppe
Copy link
Member Author

giuseppe commented Dec 6, 2023

can I get another review?

@eriksjolund
Copy link
Contributor

LGTM

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

openshift-ci bot commented Dec 6, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago, giuseppe, Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Luap99,edsantiago,giuseppe]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@edsantiago
Copy link
Member

/lgtm

I'm sorry for missing your changes yesterday.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 6, 2023
@rhatdan
Copy link
Member

rhatdan commented Dec 6, 2023

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 6, 2023
@openshift-merge-bot openshift-merge-bot bot merged commit 67aae8e into containers:main Dec 6, 2023
93 checks passed
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Mar 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support preserve-fds with non-continuous fd numbers
5 participants